import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';
//列表数据
export const columns : BasicColumn[] = [
	/* {
		title: 'trash',
		align: "center",
		dataIndex: 'trash'
	}, */
	{
		title: '是否开启',
		align: "center",
		dataIndex: 'opened',
		customRender: ({ text, record }) => {
			if (text == 1) {
				return '开启'
			} else {
				return '关闭'
			}
		}
	},
	/* 	{
			title: '路线类型',
			align: "center",
			dataIndex: 'type',
			customRender: ({ text }) => {
				if (text == 'Line') {
					return '线路'
				}
			}
		}, */
	/* 	{
			title: '租户ID',
			align: "center",
			dataIndex: 'tenantid'
		}, */
	{
		title: '目的地景点',
		align: "center",
		dataIndex: 'destinationAttractions_dictText'
	},
	{
		title: '游玩天数',
		align: "center",
		dataIndex: 'maxday'
	},
	{
		title: '预设路线名称',
		align: "center",
		dataIndex: 'prelinename'
	},
	/* 	{
			title: '合同ID',
			align: "center",
			dataIndex: 'contractid_dictText'
		},
		{
			title: '保险ID',
			align: "center",
			dataIndex: 'insuranceid'
		}, */
	{
		title: '出发城市',
		align: "center",
		dataIndex: 'cityIds_dictText',

	},
	{
		title: '图片',
		align: "center",
		dataIndex: 'images',
		customRender: ({ text }) => {
			let imgs = JSON.parse(text)
			return render.renderImage({ text: imgs.join(',') })
		},
	},

	{
		title: '准备清单',
		align: "center",
		dataIndex: 'extinfor',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.preTitle || ''
		}
	},
	{
		title: '建议出行时间段',
		align: "center",
		dataIndex: 'extinfor',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.suggestedTime || ''
		}
	},
	{
		title: '历史参与人数',
		align: "center",
		dataIndex: 'extinfor',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.historicalUserNum || ''
		}
	},
	/* 	{
			title: '其他信息',
			align: "center",
			dataIndex: 'extinfor'
		}, */
];
//查询数据
export const searchFormSchema : FormSchema[] = [
	{
		label: '出发城市',
		field: 'cityIds',
		component: 'JSelectMultiple',
		componentProps: {
			dictCode: 'sys_category,name,id,pid="1760922454642933761"',
			triggerChange: true
		},
	},
];


//表单数据
export const formSchema : FormSchema[] = [
	/* {
		label: 'trash',
		field: 'trash',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入trash!' },
			];
		},
	}, */
	{
		label: '是否开启',
		field: 'opened',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: 'openOrClose',
			triggerChange: true
		},
		required: true
	},
	/* 	{
			label: '路线类型',
			field: 'type',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入路线类型!' },
				];
			},
		}, */
	/* 	{
			label: '租户ID',
			field: 'tenantid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入租户ID!' },
				];
			},
		}, */
	/* 	{
			label: '最小天数',
			field: 'minday',
			component: 'InputNumber',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入最小天数!' },
				];
			},
		}, */
	{
		label: '目的地景点',
		field: 'destinationAttractions',
		component: 'JSearchSelect',
		componentProps: {
			dict: "BS_Scenic,title,id",
			pageSize: 10,
			async: true
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择目的地景点!' },
			];
		},
	},
	{
		label: '游玩天数',
		field: 'maxday',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入游玩数!' },
			];
		},
	},
	{
		label: '起始金额',
		field: 'startPrice',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入起始金额!' },
			];
		},
	},
	{
		label: '历史参与人数',
		field: 'historicalUserNum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入历史参与人数!' },
			];
		},
	},
	{
		label: '预设标签',
		field: 'preTags',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入预设标签!' },
			];
		},
	},
	{
		label: '预设路线名称',
		field: 'prelinename',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入预设路线名称!' },
			];
		},
	},
	{
		label: '建议出行时间段',
		field: 'suggestedTime',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入线路建议出行时间段!' },
			];
		},
	},
	{
		label: '难易等级',
		field: 'difficultyLevel',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '一级', value: '1' },
				{ label: '二级', value: '2' },
				{ label: '三级', value: '3' },
				{ label: '四级', value: '4' },
				{ label: '五级', value: '5' },
			]
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择难易等级!' },
			];
		},
	},
	{
		label: '难易等级说明',
		field: 'difficultyLevelMsg',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入难易等级说明!' },
			];
		},
	},
	{
		label: '用户发起可选择车辆',
		field: 'userSelectCars',
		component: 'ApiSelect',
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.maxday) {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getCarListByPreDayNum?maxday=' + formModel.maxday }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'leveltitle',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
					},
					//返回结果字段
					resultField: 'records'
				}
			}

		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入选择车辆!' },
			];
		},
	},

	/* 	{
			label: '合同ID',
			field: 'contractid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入合同ID!' },
				];
			},
		},
		{
			label: '保险ID',
			field: 'insuranceid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入保险ID!' },
				];
			},
		}, */
	/* 	{
			label: '出发点',
			field: 'startpoint',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入出发点!' },
				];
			},
		}, */

	{
		label: '出发城市',
		field: 'cityIds',
		component: 'JSelectMultiple',
		componentProps: {
			dictCode: 'sys_category,name,city_id,pid="1760922454642933761"',
			triggerChange: true
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入出发点!' },
			];
		},
	},

	{
		label: '图片',
		field: 'images2',
		component: 'JUpload',
		helpMessage: '最多上传20张图片',
		componentProps: {
			fileType: UploadTypeEnum.image,
			maxCount: 20,
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请上传图片!' },
			];
		},
	},

	{
		label: '可游玩景点',
		field: 'xgScenicPoint',
		component: 'InputTextArea',
		slot: 'xgScenicPoint',
		/* componentProps: {
			dictCode: 'BS_Scenic,title,id',
		}, */
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择景区!' },
			];
		},
	},
	{
		label: '准备清单',
		field: 'preId',
		component: 'JSearchSelect',
		componentProps: ({ formActionType, formModel }) => {
			return {
				dict: 'content,title,id,type_id=1764914511187304449',
				triggerChange: true,
				onChange: async (e : any, record : any) => {
					//通过这里获取准备清单的内容赋值给准备清单内
					let o = await defHttp.get({ url: '/setting/content/queryById?id=' + e })
					console.log(o)
					formModel.preMsg = o.msg
					formModel.preTitle = o.title
				}
			}
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择准备清单!' },
			];
		},
	},
	{
		label: '增值服务产品',
		field: 'pdtIds',
		component: 'JSelectMultiple',
		componentProps: {
			dictCode: "couple_shop_pdt,title,id"
		},
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择绑定产品!' },
			];
		},
	},
	{
		label: '准备清单',
		field: 'preMsg',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请编辑准备清单!' },
			];
		},
	},
	{
		label: '准备清单',
		field: 'preTitle',
		component: 'Input',
		show: false
	},
	{
		label: '推荐详情',
		field: 'msg',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入其他信息!' },
			];
		},
	},

	/* 	{
			label: '其他信息',
			field: 'extinfor',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其他信息!' },
				];
			},
		}, */
	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}



//子表列表数据
export const bsTravellinePretravellinescenicgroupColumns : BasicColumn[] = [
	{
		title: '第几天',
		align: "center",
		dataIndex: 'day'
	},
	/* 	{
			title: '预设旅游路线ID',
			align: "center",
			dataIndex: 'travellineid'
		}, */
	{
		title: '是否已排景点',
		align: "center",
		dataIndex: 'isSelectScenicPoint',
		customRender: ({ text }) => {
			if (text == 1) {
				return '已安排'
			} else {
				return '待安排'
			}
		}
	},
	/* {
		title: '景区',
		align: "center",
		dataIndex: 'scenicid_dictText'
	},
	{
		title: '默认选择',
		align: "center",
		dataIndex: 'defaultchoice_dictText'
	}, */
	/* {
		title: '第几天',
		align: "center",
		dataIndex: 'daynum'
	}, */
	/* 	{
			title: '排序',
			align: "center",
			dataIndex: 'sortorder'
		}, */
];
//子表表单数据
export const bsTravellinePretravellinescenicgroupFormSchema : FormSchema[] = [
	// TODO 子表隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '景点选择',
		field: 'scenicid',
		component: 'ApiSelect',
		componentProps: ({ formActionType, formModel }) => {
			return {
				//multiple: 多选；不填写为单选
				mode: '',
				//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
				api: () => defHttp.get({ url: '/journey/bsTravellinePlatpretravelline/getUnselectedLines' }),
				//数值转成String
				numberToString: false,
				//标题字段
				labelField: 'prelinename',
				//值字段
				valueField: 'id',
				//请求参数
				params: {
					carpoolBus: formModel.carpoolBus
				},
				//返回结果字段
				resultField: 'records'
			}

		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择预设旅游路线!' },
			];
		},
	},

	{
		label: '是否默认选择',
		field: 'defaultchoice',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入是否默认选择!' },
			];
		},
	},

	{
		label: '排序',
		field: 'sortorder',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入排序!' },
			];
		},
	},

];